import random

class Game(object):
    def __init__(self):
        self.hero = None
        self.hero_moved = False
        self.level = None
        self.messages = []
        self.quit = False
        self.turn = 0

        # Printed to the console when the game is saved or finished.
        self.quit_message = None

    def write(self, *args):
        from wormbane.model.thing import Thing
        from wormbane.util.format import render_default_message

        if len(args) == 1:
            # Plain string message.
            message = args[0]
        else:
            def definite(thing):
                return thing.mentioned
            if self.hero.hallucinating:
                observer = random.choice([arg for arg in args
                                          if isinstance(arg, Thing)] + [None])
            else:
                observer = self.hero
            message = render_default_message(observer = observer,
                                             definite = definite, *args)
        for arg in args:
            if isinstance(arg, Thing):
                arg.mentioned = True
        self.messages.append(message)
